# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Contributor: Aetf <aetf at unlimitedcodeworks dot xyz>
# Contributor: Lex Black <autumn-wind at web dot de>
# Contributor: Peng Zhang <pczhang@gmail.com>

pkgname=alglib
pkgver=3.19.0
pkgrel=1
pkgdesc="A cross-platform numerical analysis and data processing library - Free Version"
arch=('loong64' 'x86_64')
url="http://www.alglib.net"
license=('GPL2')
makedepends=('cmake')
source=(http://www.alglib.net/translator/re/alglib-${pkgver}.cpp.gpl.tgz)
sha256sums=('fbe7855f35a6a7f84538485ef7768c5442faf65e066edf85563797d65185f40f')

prepare() {
    cd "${srcdir}"/alglib-cpp

# generate a simple cmake file to build the library since the release
# doesn't provide any build system
    
    cat > CMakeLists.txt <<END
cmake_minimum_required(VERSION 3.0)
project(alglib VERSION ${pkgver})

file(GLOB SRCS src/*.cpp)
file(GLOB HEADERS src/*.h)

add_library(alglib_static STATIC \${SRCS})
set_target_properties(alglib_static PROPERTIES
    OUTPUT_NAME alglib
    PUBLIC_HEADER "\${HEADERS}"
)

add_library(alglib SHARED \${SRCS})
set_target_properties(alglib PROPERTIES
    VERSION "\${PROJECT_VERSION}"
    SOVERSION "\${PROJECT_VERSION_MAJOR}"
    PUBLIC_HEADER "\${HEADERS}"
)

include(GNUInstallDirs)
install(TARGETS alglib alglib_static
    LIBRARY DESTINATION "\${CMAKE_INSTALL_LIBDIR}"
    ARCHIVE DESTINATION "\${CMAKE_INSTALL_LIBDIR}"
    PUBLIC_HEADER DESTINATION "\${CMAKE_INSTALL_INCLUDEDIR}/libalglib"
)
install(FILES manual.cpp.html DESTINATION "\${CMAKE_INSTALL_DOCDIR}")
END

    mkdir -p build
}

build() {
    cd "${srcdir}"/alglib-cpp/build

    cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib ..
    make VERBOSE=1
}

package() {
    cd "${srcdir}"/alglib-cpp/build
    
    make DESTDIR="${pkgdir}" install
}
